package com.wangsai.framework.supersecurity.core;

import com.wangsai.framework.supersecurity.core.config.SuperSecurityConfigFactory;
import com.wangsai.framework.supersecurity.core.context.chain.UserContextFilter;
import com.wangsai.framework.supersecurity.core.config.SuperSecurityConfig;
import com.wangsai.framework.supersecurity.core.crypto.Base64UserSecure;
import com.wangsai.framework.supersecurity.core.crypto.UserSecure;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Mr.Wang
 * @date 2021-08-14 15:45
 */
public class SuperSecurityManager {

    /**
     * 配置文件 Bean
     */
    public static SuperSecurityConfig config;

    public static void setConfig(SuperSecurityConfig config) {
        SuperSecurityManager.config = config;
    }

    public static SuperSecurityConfig getConfig() {
        if (config == null) {
            synchronized (SuperSecurityManager.class) {
                if (config == null) {
                    setConfig(SuperSecurityConfigFactory.createConfig());
                }
            }
        }
        return config;
    }


    /**
     * FilterChains
     */
    public static List<UserContextFilter> userContextFilters;

    public static void setUserContextFilterChains(List<UserContextFilter> filterChains) {
        SuperSecurityManager.userContextFilters = filterChains;
    }

    public static List<UserContextFilter> getUserContextFilters() {
        if (userContextFilters == null) {
            synchronized (SuperSecurityManager.class) {
                if (userContextFilters == null) {
                    setUserContextFilterChains(new ArrayList<>());
                }
            }
        }
        return userContextFilters;
    }


    public static UserSecure userSecure;

    public static void setUserSecure(UserSecure userSecure) {
        SuperSecurityManager.userSecure = userSecure;
    }

    public static UserSecure getUserSecure() {
        if (userSecure == null) {
            synchronized (SuperSecurityManager.class) {
                if (userSecure == null) {
                    setUserSecure(new Base64UserSecure());
                }
            }
        }
        return userSecure;
    }


}